home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_tut / txt2dat.ada < prev    next >
Text File  |  1996-01-30  |  2KB  |  52 lines

  1. -- TXT2DAT.ADA   Ver. 3.00   22-AUG-1994   Copyright 1988-1994 John J. Herro
  2. -- Software Innovations Technology
  3. -- 1083 Mandarin Drive NE, Palm Bay, FL  32905-4706   (407)951-0233
  4. --
  5. -- After running DAT2TXT on a PC and transferring the resulting TUTOR.TXT
  6. -- file to another computer, compile and run this program on the other
  7. -- computer to create ADA_TUTR.DAT on that machine.
  8. --
  9. with Direct_IO, Text_IO;
  10. procedure TXT2DAT is
  11.    subtype Block_Subtype is String(1 .. 64);
  12.    package Random_IO is new Direct_IO(Block_Subtype);
  13.    Text_File  : Text_IO.File_Type;                           -- The input file.
  14.    Data_File  : Random_IO.File_Type;                        -- The output file.
  15.    OK         : Boolean := True;     -- True when both files open successfully.
  16.    Input      : String(1 .. 65);           -- Line of text read from TUTOR.TXT.
  17.    Len        : Integer;                 -- Length of line read from TUTOR.TXT.
  18.    Legal_Note : constant String := " Copyright 1988-94 John J. Herro ";
  19.                        -- Legal_Note isn't used by the program, but it causes
  20.                        -- most compilers to place this string in the .EXE file.
  21. begin
  22.    begin
  23.       Text_IO.Open(Text_File, Mode => Text_IO.In_File, Name => "TUTOR.TXT");
  24.    exception
  25.       when Text_IO.Name_Error =>
  26.          Text_IO.Put_Line(
  27.               "I'm sorry.  The file TUTOR.TXT seems to be missing.");
  28.          OK := False;
  29.    end;
  30.    begin
  31.       Random_IO.Create(Data_File, Random_IO.Out_File, Name => "ADA_TUTR.DAT");
  32.    exception
  33.       when others =>
  34.          Text_IO.Put_Line("I'm sorry.  I can't seem to create ADA_TUTR.DAT.");
  35.          Text_IO.Put_Line("Perhaps that file already exists?");
  36.          OK := False;
  37.    end;
  38.    if OK then
  39.       while not Text_IO.End_Of_File(Text_File) loop
  40.          Text_IO.Get_Line(File => Text_File, Item => Input, Last => Len);
  41.          if Len > 3 then  -- In case extra CRs/LFs were added to the text file.
  42.             Input(Len + 1 .. 64) := (others => ' ');
  43.               -- In case trailing blanks were lost when transferring TUTOR.TXT.
  44.             Random_IO.Write(Data_File, Item => Input(1 .. 64));
  45.          end if;
  46.       end loop;
  47.       Text_IO.Close(Text_File);
  48.       Random_IO.Close(Data_File);
  49.       Text_IO.Put_Line("ADA_TUTR.DAT created.");
  50.    end if;
  51. end TXT2DAT;
  52.